package com.xinqi.common.security.utils;

import com.xinqi.common.base.current.Currents;
import com.xinqi.common.base.error.CommonErrors;

import java.util.Objects;
import java.util.Optional;

/**
 * @author linkai
 * @date 2023/3/21
 */
public interface UserHelp {
    static Long userId() {
        return userId("用户未登录");
    }

    static Long userId(String msg) {
        return Optional.ofNullable(Currents.userId())
            .orElseThrow(() -> CommonErrors.BAD_REQUEST.asException(msg));
    }

    static boolean checkUser(Long userId) {
        return Objects.equals(userId(), userId);
    }

}
